<template>
  <!-- 列表 -->
  <ContentWrap>
    <el-alert class="!mb-[10px]" :closable="false">
      {{ t('settings.tips') }}
    </el-alert>
    <Editor ref="editorRef" v-loading="loading" v-model="formData.imrProfile" height="550px" />
    <el-button type="primary" class="mt-10px" :disabled="loading" @click="handleSave">{{
      t('common.save')
    }}</el-button>
  </ContentWrap>
</template>

<script setup lang="ts">
import { SettingsApi, SettingsVO } from '@/api/recruit/recruitsettings'
import { Editor } from '@/components/Editor'

/** 招生基础设置 列表 */
defineOptions({ name: 'RecruitSettingsEditor' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const formData = ref<SettingsVO>({
  id: 1,
  imrProfile: '',
  remark: ''
})
const loading = ref(true) // 列表的加载中

const getData = async () => {
  loading.value = true
  formData.value = await SettingsApi.getSettings(1)
  loading.value = false
}

const editorRef = ref<InstanceType<typeof Editor>>()
const handleSave = async () => {
  loading.value = true
  try {
    await SettingsApi.updateSettings(formData.value)
    message.success(t('common.operSuccess'))
  } finally {
    loading.value = false
  }
}

/** 初始化 **/
onMounted(() => {
  getData()
})
</script>
